<%@ page language="java" import="java.util.*" import="java.sql.*"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <he,ad>
    <base href="<%=basePath%>">
    
    <title>My JSP 'zhuce.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<title>注册</title>
  </head>
  
  <body>
  	<% 
  	String user=request.getParameter("account");
	String pwd1=request.getParameter("psd1");
	String pwd2=request.getParameter("psd2");
	Connection conn=null;
	Statement stmt=null;
	ResultSet rs=null;
	
	String url= "jdbc:mysql://localhost:3306/tsgl";
	String users = "root";
	String pass = "x5";
	
	try{
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection(url,users,pass);
		stmt = conn.createStatement();
		rs = stmt.executeQuery("select account from zhucebiao where account='"+user+"'");
		if(rs.next()){	
			out.print("账号已存在，请重新注册！");}
			else{
				if(pwd1.equals(pwd2)){
					stmt.executeUpdate("insert into zhucebiao(account,password)values('"+user+"','"+pwd1+"')");
					response.sendRedirect("createSuccess.jsp");					
				}else{
					out.print("两次输入的密码不一致，请输入正确的密码！");
				}	
			}
				
		}
	finally{
		if(rs!=null){
			rs.close();
		}
		if(stmt!=null){
			stmt.close();
		}
		if(conn!=null){
			conn.close();
		}
	}		
%>	
  
 
  </body>
</html>
